class node:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None


def postorderTravel(self, node: node):
    WHITE, GRAY = 0, 1
    ret = []
    stack = [(WHITE, node)]
    while stack:
        color, node = stack.pop()
        if node is None:
            continue
        if color == WHITE:
            stack.append((GRAY, node))
            stack.append((WHITE, node.right))
            stack.append((WHITE, node.left))
        else:
            ret.append(node.val)
    return ret
